package action;

import java.util.ArrayList;
import net.Connect;
import net.Process;
import org.apache.http.message.BasicNameValuePair;
import org.w3c.dom.Document;
import start.Info;

public class ChangeCardItems
{
  private static String URL_CHANGE_CARD_ITEMS = Info.LoginServer + "/connect/app/cardselect/savedeckcard?cyt=1";
  private static byte[] result;

  public static boolean run(String card, String lr)
    throws Exception
  {
    ArrayList al = new ArrayList();
    al.add(new BasicNameValuePair("C", card));
    al.add(new BasicNameValuePair("lr", lr));
    try {
      result = Process.connect.connectToServer(URL_CHANGE_CARD_ITEMS, al);
    } catch (Exception ex) {
      throw ex;
    }
    Document doc;
    try {
      doc = Process.ParseXMLBytes(result);
    }
    catch (Exception ex)
    {
      throw ex;
    }
    try
    {
      return parse(doc);
    } catch (Exception ex) {
      throw ex;
    }
  }

  private static boolean parse(Document doc) throws Exception
  {
    try {
      if (ExceptionCatch.catchException(doc))
        return false;
    }
    catch (Exception ex)
    {
      throw ex;
    }
    return true;
  }
}